<script lang="ts">
export default {
  name: 'l-popup'
}
</script>
<script setup lang="ts">
// import {
//   leftPositionImageUrl,
//   rightPositionImageUrl
// } from '@/pages/mine/enum/imageEnum'
import { ref, watch } from 'vue'
import { getUrl } from '@/utils/imagePlugin'
let show = ref(false)
const props = defineProps({
  modelValue: [Boolean],
  closeable: {
    type: Boolean,
    default: false
  },
  maskClickAble: {
    type: Boolean,
    default: false
  },
  isShowClose: {
    type: Boolean,
    default: false
  },
  height: {
    type: String,
    default: '500rpx'
  },
  title: {
    type: String,
    default: ''
  }
})
const emit = defineEmits<{
  (e: 'update:modelValue', event: any): void
}>()
const close = () => {
  show.value = false
}
watch(
  () => props.modelValue,
  (val) => {
    show.value = val
  },
  {
    immediate: true
  }
)
watch(
  () => show.value,
  (val) => {
    emit('update:modelValue', val)
  },
  {
    immediate: true
  }
)
</script>
<template>
  <u-mask
    :show="show"
    @click.stop="close"
    :mask-click-able="maskClickAble"
    :custom-style="{ background: 'rgba(0, 0, 0, 0.2)' }"
  >
    <view v-if="show" class="modal">
      <view class="box">
        <view class="imageBox">
          <u-image
            :src="getUrl('/topBackGround.png')"
            mode="widthFix"
            width="100%"
            height="100%"
          ></u-image>
        </view>
        <view class="contentAllBox">
          <view class="closeBtn" v-if="isShowClose" @click.stop="close">
            <u-image
              :src="getUrl('/close.png')"
              mode="widthFix"
              width="100%"
              height="100%"
            ></u-image>
          </view>
          <view
            class="contentBox"
            :style="`height: ${height};background-image: url(${getUrl('/contentBackGround.png')}) ;background-size: 100% 100%; background-position: center; background-color:unset;background-repeat: no-repeat; box-sizing: border-box;`"
          >
            <view class="flexContentTitleBox" v-if="title">
              <view class="titleImageBox">
                <u-image :src="leftPositionImageUrl" mode="widthFix"></u-image>
              </view>
              <view class="center">{{ title }}</view>
              <view class="titleImageBox">
                <u-image :src="rightPositionImageUrl" mode="widthFix"></u-image>
              </view>
            </view>

            <view class="contentScrollBox">
              <slot></slot>
            </view>
          </view>
        </view>

        <view class="imageBox bottomBox">
          <u-image
            :src="getUrl('/bottomBackGround.png')"
            mode="widthFix"
            width="100%"
            height="100%"
          ></u-image>
        </view>
      </view>
    </view>
  </u-mask>
</template>

<style scoped lang="scss">
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 99;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  .box {
    width: 550rpx;
    .contentAllBox {
      padding: 0 20rpx;
      box-sizing: border-box;
      position: relative;
      .closeBtn {
        position: absolute;
        right: 20rpx;
        top: -105rpx;
        width: 50rpx;
        height: 50rpx;
      }
    }
    .contentBox {
      padding: 30rpx 30rpx;
      width: 100%;
      box-sizing: border-box;
      display: flex;
      flex-direction: column;
      .flexContentTitleBox {
        display: flex;
        justify-content: center;
        align-items: flex-end;
        .center {
          margin: 0 11rpx;
          color: #947a61;
          font-weight: bold;
          font-size: 32rpx;
        }
        .titleImageBox {
          width: 53rpx;
          height: 36rpx;
        }
      }
      .contentScrollBox {
        overflow: auto;
        flex: 1;
      }
    }
    .bottomBox {
      margin-top: -20rpx;
    }
    .imageBox {
      width: 100%;
      height: 34rpx;
    }
  }
}
</style>
